<?php
// +----------------------------------------------------------------------
// | EtrolPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Author:HCZ <huangchengze@etrol.com>
// +-----------------------------------------------------------------------

namespace app\common\model;

use app\common\model\Base;
/**
 * 系统配置
 */
class Config extends Base{
	protected $name = 'config';
	protected $createTime = 'createTime';
	protected $updateTime = 'updateTime';
	public $type = [1=>'string',2=>'text',3=>'array'];
	

	public function lists(){
		$data   = $this->db()->field('type,name,value,groupName')->select();
	
		$config = array();
		if($data && is_array($data)){
			foreach ($data as $value) {
				$config[$value['groupName']][$value['name']]= $this->parse($value['type'], $value['value']);
			}
		}
		return $config;
	}
	
	/**
	 * 根据配置类型解析配置
	 * @param  integer $type  配置类型
	 * @param  string  $value 配置值
	 * @author HCZ <huangchengze@etrol.com>
	 */
	private function parse($type, $value){
		switch ($type) {
			case '3': //解析数组
				$value = explode(',',$value);
				break;
		}
		return $value;
	}
}